/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.*;
import java.util.Random;

/**
 * <p>Project: javaseapp - C
 * <p>Powered by webrx On 2021-09-04 09:24:39
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class C {
    public static void main(String[] args) {
        //字节流
        long start = System.currentTimeMillis();
        try (FileInputStream fis = new FileInputStream("c:/user.log")) {
            //System.out.println(new String(fis.readAllBytes()));
            //fis.readAllBytes();
            StringBuilder sbu = new StringBuilder();
            int b = 0;
            while ((b = fis.read()) != -1) {
                sbu.append((char) b);
            }
            System.out.println(sbu.toString());
        } catch (Exception e) {

        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        //字符流
        start = System.currentTimeMillis();
        Reader in;
        try (BufferedReader br = new BufferedReader(new FileReader("c:/user.log"))) {
            while (br.ready()) {
                br.readLine();
                //System.out.println(br.readLine());
            }
        } catch (Exception e) {

        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void ok() {
        File file;
        Random rand = new Random();
        try (FileWriter fw = new FileWriter("c:/user.log")) {
            for (int i = 1; i <= 10000; i++) {
                fw.write(String.format("%d、", i) + getStr(rand.nextInt(50) + 10) + "\r\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getStr(int n) {
        String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder sbu = new StringBuilder();
        Random rand = new Random();
        for (int i = 0; i < n; i++) {
            sbu.append(letter.charAt(rand.nextInt(letter.length())));
        }
        return sbu.toString();
    }
}
